package cn.tt.tuantuanerp;

import cn.tt.tuantuanerp.mapper.PurchaseMapper;
import cn.tt.tuantuanerp.pojo.dto.PurchaseStandardDTO;
import cn.tt.tuantuanerp.pojo.entity.Purchase;
import cn.tt.tuantuanerp.pojo.vo.PurchaseStandardVO;
import cn.tt.tuantuanerp.passport.LoginPrincipal;
import cn.tt.tuantuanerp.service.PurchaseService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;


@Slf4j
@SpringBootTest
public class tests {
    @Autowired
    PurchaseMapper mapper;
    @Autowired
    LoginPrincipal loginPrincipal;

    @Autowired
    PurchaseService service;
    @Test
    void  insert(){
        Purchase purchase=new Purchase ();
        purchase.setPurchaseId ( "123456" );
        //
        purchase.setRateType ( "个人所得税" );
        //
        purchase.setTaxRate ( new BigDecimal(0.12d) );
        //
        purchase.setBillType ( 1);
        purchase.setTotalMoney ( new BigDecimal(5000000d));
        purchase.setTotalMoneyBefore ( new BigDecimal(5000000d) );
        purchase.setTaxTotalMoney ( new BigDecimal(5000000d) );
        //
        purchase.setNotInStockAmount ( 560 );

        purchase.setOrderTime ( LocalDateTime.now () );
        purchase.setEntryEmployee ( "zzz" );
        purchase.setLastEntryTime (  LocalDateTime.now ());
        purchase.setPurchasesEmployee ( "zzz" );
        purchase.setPurchasesState ( 0 );
        purchase.setTaxGold (new BigDecimal(5000000d));
        purchase.setAmountPaid (new BigDecimal(5000000d)  );
        purchase.setAmountOutstanding (new BigDecimal(5000000d));
        purchase.setSupplierId ( 123456);
        purchase.setPartOrder ("zms");
        purchase.setCountProduct ( 15000 );
        int i = mapper.insertPurchase ( purchase );
        log.debug ( "受影响行数：{}",i );

    }

   // @Test
//    void  insertBatch(){
//        List<Purchase>list=new ArrayList<> ();
//        for(int i=1;i<3;i++){
//            Purchase purchase=new Purchase ();
//            purchase.setPurchaseId ( 12345L+i );
//            //
//            purchase.setRateType ( "个人所得税" );
//            //
//            purchase.setTaxRate ( 0.12d );
//            //
//            purchase.setBillType ( 1L);
//            purchase.setTotalMoney ( 50000000d);
//            purchase.setTotalMoneyBefore ( 60000000d );
//            purchase.setTaxTotalMoney ( 6000000001d );
//            //
//            purchase.setNotInStockAmount ( 560L );
//
//            purchase.setOrderTime ( LocalDateTime.now () );
//            purchase.setEntryEmployee ( "zzz" );
//            purchase.setLastEntryTime (  LocalDateTime.now ());
//            purchase.setPurchasesEmployee ( "zzz" );
//            purchase.setPurchasesState ( 0L );
//            purchase.setTaxGold ( 202222d );
//            purchase.setAmountPaid ( 500000d );
//            purchase.setAmountOutstanding (5000000d);
//            purchase.setSupplier ( "heller" );
//            purchase.setPartOrder ("zms");
//            purchase.setCountProduct ( "20000" );
//            list.add ( purchase );
//        }
//        int i = mapper.insertBatchPurchase ( list );
//
//        log.debug ( "受影响行数：{}",i );
//
//    }
//
//    @Test
//    void deletePurchase(){
//       Long []id={12346L,12347L};
//       mapper.deleteBatchPurchase (  id);
//    }
//
//    @Test
//    void selectById(){
//        Long id=123456L;
//        PurchaseStandardVO purchaseById = mapper.getPurchaseById ( id );
//        log.debug ( "获取的数据：{}",purchaseById );
//    }

//    @Test
//    void service(){
//        PurchaseStandardDTO purchase=new PurchaseStandardDTO();
//        purchase.setPurchaseId ( "1234568 ");
//        //
//        purchase.setRateType ( "个人所得税" );
//        //
//        purchase.setTaxRate ( 0.12 );
//        //
//        purchase.setBillType ( 1);
//        purchase.setTotalMoney ( 5000000d);
//        purchase.setTotalMoneyBefore ( 50000d );
//        purchase.setTaxTotalMoney ( 500000d );
//        //
//        purchase.setNotInStockAmount ( 560 );
//
//        purchase.setOrderTime ( LocalDateTime.now () );
//        purchase.setEntryEmployee ( "zzz" );
//        purchase.setLastEntryTime (  LocalDateTime.now ());
//        purchase.setPurchasesEmployee ( "zzz" );
//        purchase.setPurchasesState ( 0);
//        purchase.setTaxGold (50000d);
//        purchase.setAmountPaid (5000000d );
//        purchase.setAmountOutstanding (500d);
//        purchase.setSupplierId ( 123456);
//        purchase.setPartOrder ("zms");
//        purchase.setCountProduct ( 15000 );
//        service.addPurchase(purchase);
//    }

    @Test
    void update(){
        Purchase purchase=new Purchase ();
        purchase.setPurchaseId ( "1234567 ");
        service.updateStateToPurchasing ( purchase.getPurchaseId () );
    }


    @Test
    void select(){
        PurchaseStandardVO cg20220102 = mapper.getPurchaseById("CG20220102");
        System.out.println(cg20220102);
    }


//    @Test
//    void delete(){
//      service.deletePurchase("CG20221027125100045.118",loginPrincipal);
//    }
}